home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / 11.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  4KB  |  151 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #include "hdr.h"
  10. #include "vars.h"
  11. #include "smiscp.h"
  12. #include "miscp.h"
  13. #include "setp.h"
  14. #include "errmsgp.h"
  15. #include "chapp.h"
  16.  
  17. void except_decl(Node id_list_node)                            /*;except_decl*/
  18. {
  19.     Node    id_node;
  20.     Symbol    name;
  21.     Fortup    ft1;
  22.  
  23.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  except_decl");
  24.  
  25.     FORTUP(id_node = (Node), N_LIST(id_list_node), ft1);
  26.         name = find_new(N_VAL(id_node));
  27.         N_UNQ(id_node) = name;
  28.         NATURE(name) = na_exception;
  29.         TYPE_OF(name) = symbol_exception;
  30.     ENDFORTUP(ft1);
  31. }
  32.  
  33. void exception_part(Node node)                            /*;exception_part*/
  34. {
  35.     Symbol    handler;
  36.  
  37.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  exception_part'");
  38.  
  39.     /* A scope is established for the exception handlers. This scope
  40.      * or a block nested within it, are the only valid scopes for the
  41.      * occurence of a non-specific RAISE statement.
  42.      */
  43.  
  44.     handler = find_new(newat_str());
  45.     newscope(handler);
  46.     /*SYMBTAB(handler) := [na_block, 'handler', []];*/
  47.     NATURE(handler) = na_block;
  48.     OVERLOADS(handler) = (Set) BLOCK_HANDLER;
  49.     SIGNATURE(handler) = tup_new(0);
  50.  
  51.     /* Process individual handlers.*/
  52.     sem_list(node);
  53.  
  54.     popscope();
  55. }
  56.  
  57. void exception_handler(Node node)                    /*;exception_handler*/
  58. {
  59.     Node    excp_list_node, statements_node, name_node;
  60.     Tuple    exception_list;
  61.     Symbol    except;
  62.     Fortup    ft1;
  63.  
  64.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  exception_handler");
  65.  
  66.     excp_list_node = N_AST1(node);
  67.     statements_node = N_AST2(node);
  68.     exception_list = N_LIST(excp_list_node);
  69.     FORTUP(name_node = (Node), exception_list, ft1);
  70.         adasem(name_node);
  71.  
  72.         if (N_KIND(name_node) != as_others) {
  73.             find_old(name_node);
  74.             except = N_UNQ(name_node);
  75.                         /* except is (Symbol)0 in the case that name_node is 
  76.                          * a selector whose prefix is a parameterless function 
  77.                          * This error condition is not caught by find_old
  78.                          */
  79.             if (except == (Symbol)0) {
  80.                    errmsg("Invalid exception name in handler", 
  81.                                        "11.1", name_node);
  82.                         }
  83.                         else if (NATURE(except) != na_exception) {
  84.                 errmsg_id("% is not an exception", except, "11.1", name_node);
  85.             }
  86.             else if (tup_mem((char *) except, SIGNATURE(scope_name)) ) {
  87.                 errmsg("Duplicate exception name in handler", "11.2",name_node);
  88.             }
  89.             else {
  90.                 SIGNATURE(scope_name) = tup_with(SIGNATURE(scope_name),
  91.                   (char *) except);
  92.             }
  93.         }
  94.         else {
  95.             /* The use of 'others' in SETL is just as a marker for local
  96.              * processing. Use the null symbol pointer in C version.
  97.              */
  98.             if (tup_mem((char *)0, SIGNATURE(scope_name)) ) {
  99.                 errmsg("Duplicate OTHERS in exception part", "11.2", name_node);
  100.             }
  101.             else if (tup_size(exception_list) == 1)
  102.                 SIGNATURE(scope_name) = tup_with(SIGNATURE(scope_name),
  103.                   (char *)0);
  104.         }
  105.     ENDFORTUP(ft1);
  106.  
  107.     adasem(statements_node);
  108. }
  109.  
  110. void raise_statement(Node node)                            /*;raise_statement*/
  111. {
  112.     Node    name_node;
  113.     Symbol    scope, except;
  114.     int    exists;
  115.     Fortup    ft1;
  116.  
  117.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  raise_statement");
  118.  
  119.     name_node = N_AST1(node);
  120.  
  121.     if (name_node == OPT_NODE) {
  122.         /* Non-specific raise. This statement form can appear only within
  123.          * an exception handler.
  124.          */
  125.         exists = FALSE;
  126.  
  127.         FORTUP(scope = (Symbol), open_scopes, ft1);
  128.             if(NATURE(scope) != na_block
  129.               || (int)OVERLOADS(scope) == BLOCK_HANDLER) {
  130.                 exists = TRUE;
  131.                 break;
  132.             }
  133.         ENDFORTUP(ft1);
  134.         if (!exists) chaos("assert error in raise_statement");
  135.  
  136.         if ((int)OVERLOADS(scope) != BLOCK_HANDLER) {
  137.             errmsg("RAISE statement not directly in exception handler", "11.3",
  138.               node);
  139.         }
  140.     }
  141.     else {
  142.         adasem(name_node);
  143.         find_old(name_node);
  144.         except = N_UNQ(name_node);
  145.         if ( except == (Symbol)0
  146.           || NATURE(except) != na_exception && TYPE_OF(except) != symbol_any) {
  147.             errmsg("Invalid exception name", "11.1", name_node);
  148.         }
  149.     }
  150. }
  151.